package com.bigdata.service.controller.app;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.bigdata.common.annotation.Log;
import com.bigdata.common.annotation.RepeatSubmit;
import com.bigdata.common.core.controller.BaseController;
import com.bigdata.common.core.domain.PageQuery;
import com.bigdata.common.core.domain.R;
import com.bigdata.common.core.page.TableDataInfo;
import com.bigdata.common.core.validate.AddGroup;
import com.bigdata.common.core.validate.EditGroup;
import com.bigdata.common.enums.BusinessType;
import com.bigdata.common.utils.poi.ExcelUtil;
import com.bigdata.service.domain.Datasets;
import com.bigdata.service.domain.bo.UserCollectionsBo;
import com.bigdata.service.domain.vo.UserCollectionsVo;
import com.bigdata.service.service.IUserCollectionsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 用户收藏
 *
 * @author ruoyi
 * @date 2025-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/service/collections")
public class AppUserCollectionsController extends BaseController {

    private final IUserCollectionsService iUserCollectionsService;

    /**
     * 查询用户收藏列表
     */
    @SaIgnore
    @PostMapping("/list")
    public TableDataInfo<Datasets> list(@RequestBody UserCollectionsBo bo) {
        return iUserCollectionsService.selectUserCollectionsPageList(bo);
    }


    /**
     * 新增用户收藏
     */

    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserCollectionsBo bo) {
        bo.setUserId(getUserId());
        bo.setCollectionTime(new Date());
        bo.setCollectionStatus("active");
        return toAjax(iUserCollectionsService.insertByBo(bo));
    }

    /**
     * 修改用户收藏
     */

    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserCollectionsBo bo) {
        bo.setCollectionStatus("deleted");
        return toAjax(iUserCollectionsService.updateByBo(bo));
    }
}
